package com.aierjun.camera.record;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MotionEvent;
import android.view.TextureView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SeekBar;

import com.aierjun.camera.R;
import com.aierjun.camera.widget.FocusImageView;
import com.aierjun.camera.widget.RecordCameraView;


public class RecordActivity extends AppCompatActivity {
    private RecordCameraView cameraView;
    /**
     * 触摸屏幕时显示的聚焦图案
     */
    private FocusImageView focusImageView;

    private ImageView shutterImageView;

    private ImageView backImageView;

    private RelativeLayout controller_rl;

    private ImageView btn_flashlight;

    private ImageView btn_lenses;

    private int cameraWidth, cameraHeight, controllerHeight;

    private SeekBar zoom_seekbar;

    private TextureView textureView;

    private ImageView okImageView;

    private RecordVideoManager recordVideoManager;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);
        findView();
        initView();
    }

    private void findView() {
        cameraView = findViewById(R.id.cameraView);
        focusImageView = findViewById(R.id.focusImageView);
        backImageView = findViewById(R.id.backImageView);
        okImageView = findViewById(R.id.okImageView);
        shutterImageView = findViewById(R.id.shutterImageView);
        controller_rl = findViewById(R.id.controller_rl);
        btn_flashlight = findViewById(R.id.btn_flashlight);
        btn_lenses = findViewById(R.id.btn_lenses);
        zoom_seekbar = findViewById(R.id.zoom_seekbar);
        textureView = findViewById(R.id.textureView);
    }

    private void initView() {
        recordVideoManager = RecordVideoManager.getInstance(this);
        recordVideoManager.initCamera(cameraView)
            .initFocusImageView(focusImageView)
            .initSensorControler()
            .initTextureView(textureView)
            .initControllerRLChildView(controller_rl, backImageView, shutterImageView, btn_lenses, btn_flashlight, okImageView)
            .initZoomSeekBar(zoom_seekbar)
            .setSaveCallBackPathLister(new SaveCallBackPathLister() {
                @Override
                public void callBackPath(String path) {
                    Intent intent = new Intent();
                    intent.putExtra("videopath", path);
                    //返回成功给DemoActivity界面
                    setResult(RESULT_OK, intent);
                    finish();
                }
            });
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return recordVideoManager.onTouchEvent(event);
    }

    @Override
    protected void onStart() {
        recordVideoManager.onStart();
        super.onStart();
    }

    @Override
    protected void onStop() {
        recordVideoManager.onStop();
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        recordVideoManager.onDestroy();
        super.onDestroy();
    }

}
